package com.moss.cloud.base.biz.controller;

import com.moss.cloud.base.api.model.from.AddMenuFrom;
import com.moss.cloud.base.api.model.from.BaseFrom;
import com.moss.cloud.base.api.model.from.EditMenuFrom;
import com.moss.cloud.base.biz.service.ISysMenuService;
import com.moss.cloud.common.core.constant.ServiceList;
import com.moss.cloud.common.core.model.Result;
import com.moss.cloud.common.security.annotation.SysLog;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 菜单管理前端控制器
 *
 * @author 瑾年
 * @date 2023年3月23日
 */
@RestController
@RequestMapping(ServiceList.BASE + "/sysMenu")
public class SysMenuController {

    private ISysMenuService sysMenuService;
    public SysMenuController(ISysMenuService sysMenuService){
        this.sysMenuService = sysMenuService;
    }

    /**
     * 查询当前登录人的菜单树
     *
     * @return
     */
    @PostMapping("/menuTree")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "查询当前登录人的菜单树")
    public Result<?> menuTree(){
        return Result.success(sysMenuService.menuTree());
    }

    /**
     * 获取菜单信息
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/menuInfo")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "获取菜单信息")
    public Result<?> menuInfo(@RequestBody @Validated BaseFrom baseFrom){
        return Result.success(sysMenuService.menuInfo(baseFrom));
    }

    /**
     * 编辑菜单
     *
     * @param editMenuFrom
     * @return
     */
    @PostMapping("/editSysMenu")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "编辑菜单")
    public Result<?> editSysMenu(@RequestBody @Validated EditMenuFrom editMenuFrom){
        return Result.success(sysMenuService.editSysMenu(editMenuFrom));
    }

    /**
     * 添加菜单
     *
     * @param addMenuFrom
     * @return
     */
    @PostMapping("/addSysMenu")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "添加菜单")
    public Result<?> addSysMenu(@RequestBody @Validated AddMenuFrom addMenuFrom){
        return Result.success(sysMenuService.addSysMenu(addMenuFrom));
    }

    /**
     * 删除菜单
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/delSysMenu")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "删除菜单")
    public Result<?> removeSysMenu(@RequestBody @Validated BaseFrom baseFrom){
        return Result.success(sysMenuService.removeSysMenu(baseFrom));
    }

    /**
     * 刷新资源池
     *
     * @return
     */
    @PostMapping("/refreshSysMenu")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "刷新资源池")
    public Result<?> refreshSysMenu(){
        return Result.success(sysMenuService.refreshSysMenu());
    }
}
